﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;

namespace Tomahawk.Runtime.Rendering.Particles
{
    public class ParticleSourceRectangle : ParticleSource
    {
        #region Serializable Properties
        [XmlElement("InnerExtents")]
        public Vector2 innerExtents = Vector2.Zero;
        [XmlElement("OuterExtents")]
        public Vector2 outerExtents = Vector2.Zero;
        [XmlElement("Velocity")]
        public Vector3 velocity = Vector3.Zero;
        #endregion

        public override Vector3 GenerateParticlePosition(ref Matrix worldMatrix)
        {
            double width = innerExtents.X + ParticleSystem.Random.NextDouble() * (outerExtents.X - innerExtents.X);
            double height = innerExtents.Y + ParticleSystem.Random.NextDouble() * (outerExtents.Y - innerExtents.Y);

            Vector3 position = Vector3.Zero;
            position.X = (float) width;
            position.Z = (float) height;

            return Vector3.Transform(position, worldMatrix);
        }

        public override Vector3 GenerateParticleVelocity(ref Matrix worldMatrix)
        {
            return Vector3.TransformNormal(AddNoiseToVelocity(ref velocity), worldMatrix);
        }
    }
}
